package org.goldenport.g3.messages.filestore

import java.io._
import org.goldenport.g3.G3Message

/**
 * @since   Apr. 12, 2010
 * @version Sep. 18, 2010
 * @author  ASAMI, Tomoharu
 */
/**
 * Creates a file.
 */
case class Create(path: String) extends G3Message {
  def openInputStream(): Option[InputStream] = None
}

/**
 * Reads whole data from the file.
 */
case class Read(path: String) extends G3Message

/**
 * Writes whole data into the file.
 */
abstract class Write(val path: String) extends G3Message {
  def openInputStream(): InputStream
  val text: String
  val encoding: String = "utf-8"
}

class StringWrite(path: String, val text: String) extends Write(path) {
  def openInputStream() = {
    new ByteArrayInputStream(text.getBytes(encoding))
  }
}

object Write {
  def apply(path: String, string: String) = {
    new StringWrite(path, string)
  }
}

/**
 * Removes the file.
 */
case class Remove(path: String)
